package com.xiebishe.mylibrary.common.dialog.loading;

import android.content.Context;
import android.view.Gravity;
import android.view.WindowManager;

import androidx.annotation.LayoutRes;
import androidx.appcompat.app.AppCompatDialog;

import com.xiebishe.mylibrary.R;
import com.xiebishe.mylibrary.base.MyActivityManager;
import com.xiebishe.mylibrary.common.WindowUtils;


class LoadingDialog extends AppCompatDialog {

    public LoadingDialog(Context context) {
        super(context, R.style.loadingDialog);
        initView();
        initLayout();
    }

    public LoadingDialog(Context context, @LayoutRes int layoutResID) {
        super(context, R.style.loadingDialog);
        initView();
        setContentView(layoutResID);
    }

    private void initView() {
        setContentView(R.layout.dialog_loading);
    }

    private void initLayout() {
        getWindow().setGravity(Gravity.CENTER);
        WindowManager.LayoutParams p = getWindow().getAttributes();
        p.width = WindowManager.LayoutParams.MATCH_PARENT;
        p.height = WindowManager.LayoutParams.MATCH_PARENT;
        getWindow().setAttributes(p);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
        //全屏，statusBar和activity相同、荣耀note10，activity是darkStatus会有灰色蒙层
        WindowUtils.setTransparentStatusBarAndFullScreen(getWindow());
        getWindow().getDecorView().setSystemUiVisibility(MyActivityManager.getInstance().getCurrentActivity().getWindow().getDecorView().getSystemUiVisibility());
        setCancelable(false);
    }
}
